package com.wc.算法提高课.C第三章_图论.最近公共祖先.暗之连锁;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/19 16:35
 * @description https://www.acwing.com/problem/content/description/354/
 */
public class Main {
    /**
     * 思路：lca + 树上差分<p>
     * 树上差分 计算某一个点自己的数值手, 需要用到子树来计算<p>
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010, M = N << 1, INF = 0x3f3f3f3f;
    static int[] h = new int[N], e = new int[M], ne = new int[M];
    static int[] d = new int[N], q = new int[N], depth = new int[N];
    static int[][] f = new int[N][17];
    static int n, m, idx = 1, ans = 0;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i < n; i++) {
            int a = sc.nextInt(), b = sc.nextInt();
            add(a, b);
            add(b, a);
        }
        bfs();
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt(), b = sc.nextInt();
            int p = lca(a, b);
            d[a]++;
            d[b]++;
            d[p] -= 2;
        }
        dfs(1, -1);
        out.println(ans);
        out.flush();
    }

    static int dfs(int u, int fa) {
        int res = d[u];
        for (int i = h[u]; i > 0; i = ne[i]) {
            int j = e[i];
            if (j == fa) continue;
            int s = dfs(j, u);
            if (s == 0) ans += m;
            else if (s == 1) ans += 1;
            res += s;
        }
        out.println(u + " " + res);
        return res;
    }

    static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }

    static void bfs() {
        Arrays.fill(depth, 1, n + 1, INF);
        int hh = 0, tt = 1;
        depth[0] = 0;
        depth[1] = 1;
        q[0] = 1;
        while (hh < tt) {
            int t = q[hh++];
            for (int i = h[t]; i > 0; i = ne[i]) {
                int j = e[i];
                if (depth[j] > depth[t] + 1) {
                    depth[j] = depth[t] + 1;
                    q[tt++] = j;
                    f[j][0] = t;
                    for (int k = 1; k <= 16; k++) {
                        f[j][k] = f[f[j][k - 1]][k - 1];
                    }
                }
            }
        }
    }

    static int lca(int a, int b) {
        if (depth[a] < depth[b]) return lca(b, a);
        for (int k = 16; k >= 0; k--) {
            if (depth[f[a][k]] >= depth[b]) a = f[a][k];
        }
        if (a == b) return b;
        for (int k = 16; k >= 0; k--) {
            if (f[a][k] != f[b][k]) {
                a = f[a][k];
                b = f[b][k];
            }
        }
        return f[a][0];
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
